package com.scf.fruit.commodity.impl;

import com.scf.fruit.commodity.CommodityDto;
import com.scf.fruit.commodity.CommodityService;
import com.scf.fruit.commodity.dao.CommodityMapper;
import com.scf.fruit.enums.StatusEnum;
import com.scf.fruit.util.IDUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @copyright :润投科技
 * @date : 2018-05-21 15:35
 */
@Service
public class CommodityServiceImpl implements CommodityService{
    @Resource
    private CommodityMapper commodityMapper;
    @Override
    public List<CommodityDto> queryCommodityByPage() {
        CommodityDto dto=new CommodityDto();
        dto.setDeleteFlag(StatusEnum.YES.getValue());
        return commodityMapper.select(dto);
    }

    @Override
    public List<CommodityDto> queryCommodityByType(Integer type) {
        CommodityDto dto=new CommodityDto();
        dto.setDeleteFlag(StatusEnum.YES.getValue());
        dto.setType(type);
        return commodityMapper.select(dto);
    }

    @Override
    public boolean insertCommodity(CommodityDto dto) {
        dto.setCreateTime(new Date());
        dto.setDeleteFlag(StatusEnum.YES.getValue());
        dto.setId(IDUtil.getId());
        return commodityMapper.insert(dto)>0;
    }

    @Override
    public boolean updateCommodity(CommodityDto dto) {
        if(null==dto.getId())
        {
            return false;
        }
        dto.setUpdateTime(new Date());
        return commodityMapper.updateByPrimaryKeySelective(dto)>0;

    }

    @Override
    public boolean deleteCommodity(CommodityDto dto) {
        if(null==dto.getId())
        {
            return false;
        }
       dto.setUpdateTime(new Date());
        return commodityMapper.updateByPrimaryKeySelective(dto)>0;
    }
}
